import { ref } from 'vue'
import { defineStore } from 'pinia'
import axios from 'axios'

export const useJokerStore = defineStore('Joker', () => {
  // 保存笑话
  const joke = ref('笑死了')

  // 刷新笑话，并替换默认值
  function refreshJoke() {
    // 调用接口获取笑话
    axios.get('https://api-vue-base.itheima.net/api/joke').then((res) => {
      joke.value = res.data
    })
  }

  // 一次性返回
  return { joke, refreshJoke }
})
